package com.pearadmin.modules.html.controller;

import com.pearadmin.common.plugins.resource.service.IFileService;
import com.pearadmin.modules.blog.service.IArticleService;
import com.pearadmin.modules.blog.service.IBannerService;
import com.pearadmin.modules.blog.service.ILabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("html")
public class HtmlController {

    @Autowired
    IBannerService bannerService;

    @Autowired
    ILabelService labelService;

    @Autowired
    IArticleService articleService;


    @GetMapping({"index",""})
    public String index(ModelMap map){

        map.put("bannerList",bannerService.findTop5());
        map.put("articleList",articleService.findTop10());
        System.out.println(labelService.selectAll().toString());

        map.put("labels",labelService.selectAll());
        return "html/index";
    }

    /**
     * 图片详情
     */
    @Resource
    private IFileService fileService;
    @GetMapping("file/download/{id}")
    public void download(@PathVariable("id") String id){
        fileService.download(id);
    }

}
